﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ISSMoviePlex.DAL.Repositories;
using ISSMoviePlex.DAL.Models;

namespace ISSMoviePlex.BLL
{
    public class RoomBLL
    {
        private readonly RoomRepository _roomRepository;
        private readonly ScheduleRepository _schRepository;

        public RoomBLL()
        {
            _roomRepository = RoomRepository.Instance;
            _roomRepository.Initialize();
            _schRepository = ScheduleRepository.Instance;
            _schRepository.Initialize();
        }

        public List<Room> GetAllRooms()
        {
            return _roomRepository.GetAll().ToList();
        }

        public bool ValidateRoomAvailable(int scheduleId,ref string errorMsg)
        {
            var room = _schRepository.FindById(scheduleId).Room;
            if (room != null)
            {
                errorMsg = "Sorry!The room is already assigned";
                return false;
            }
            return true;
        }

        public void AddRoom(Room room)
        {
            _roomRepository.Add(room);
            _roomRepository.Save();
        }

        public void UpdateRoom(Room room)
        {
            _roomRepository.Edit(room);
            _roomRepository.Save();
        }

        public void DeleteRoom(Room room)
        {
            _roomRepository.Delete(room);
            _roomRepository.Save();
        }
    }
}
